{% extends "base_generic.html" %}

{% block title %}Delete Book - {{ block.super }}{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-danger text-white">
                    <h4 class="mb-0">
                        <i class="bi bi-exclamation-triangle me-2"></i>
                        Delete Book
                    </h4>
                </div>
                <div class="card-body">
                    <h5>Are you sure you want to delete "{{ object.title }}"?</h5>
                    <div class="alert alert-warning">
                        <i class="bi bi-info-circle me-2"></i>
                        <strong>Warning:</strong> This action cannot be undone and will delete:
                        <ul class="mb-0 mt-2">
                            <li>The book itself</li>
                            <li>All {{ total_instances }} book cop{{ total_instances|pluralize:"y,ies" }}</li>
                            <li>All {{ total_borrow_records }} borrowing record{{ total_borrow_records|pluralize:"s" }}</li>
                            {% if borrowed_instances %}
                                <li><strong>{{ borrowed_instances.count }} borrowed cop{{ borrowed_instances.count|pluralize:"y,ies" }} will be automatically returned</strong></li>
                            {% endif %}
                        </ul>
                    </div>
                    
                    {% if borrowed_instances %}
                        <div class="alert alert-info">
                            <h6><i class="bi bi-info-circle me-2"></i>Currently Borrowed Copies</h6>
                            <p>The following {{ borrowed_instances.count }} cop{{ borrowed_instances.count|pluralize:"y,ies" }} 
                               {{ borrowed_instances.count|pluralize:"is,are" }} currently borrowed and will be automatically returned:</p>
                            <ul class="mb-2">
                                {% for instance in borrowed_instances %}
                                    <li>
                                        Copy {{ instance.id|slice:":8" }}...
                                        {% if instance.borrower %}
                                            - Borrowed by <strong>{{ instance.borrower.username }}</strong>
                                            {% if instance.due_back %}
                                                (Due: {{ instance.due_back }})
                                            {% endif %}
                                        {% endif %}
                                    </li>
                                {% endfor %}
                            </ul>
                            <p class="mb-0 text-muted">
                                <small><i class="bi bi-exclamation-triangle me-1"></i>These users will need to be notified that their books have been recalled.</small>
                            </p>
                        </div>
                    {% endif %}
                    
                    <div class="book-info p-3 mb-3 bg-light rounded">
                        <h6><strong>{{ object.title }}</strong></h6>
                        <p class="mb-1"><strong>Author(s):</strong> 
                            {% for author in object.author.all %}
                                {{ author.get_full_name }}{% if not forloop.last %}, {% endif %}
                            {% empty %}
                                No authors listed
                            {% endfor %}
                        </p>
                        <p class="mb-1"><strong>ISBN:</strong> {{ object.isbn }}</p>
                        {% if object.genre.all %}
                            <p class="mb-1"><strong>Genres:</strong>
                                {% for genre in object.genre.all %}
                                    <span class="badge bg-secondary me-1">{{ genre.name }}</span>
                                {% endfor %}
                            </p>
                        {% endif %}
                        <p class="mb-0"><strong>Total Copies:</strong> {{ total_instances }}</p>
                    </div>
                    
                    {% if book_instances %}
                        <div class="alert alert-secondary">
                            <h6><i class="bi bi-list me-2"></i>All Book Copies to be Deleted</h6>
                            <ul class="mb-0">
                                {% for instance in book_instances %}
                                    <li>
                                        Copy {{ instance.id|slice:":8" }}... - Status: 
                                        <span class="badge bg-{% if instance.status == 'a' %}success{% elif instance.status == 'o' %}danger{% elif instance.status == 'm' %}secondary{% else %}warning{% endif %}">
                                            {{ instance.get_status_display }}
                                        </span>
                                        {% if instance.status == 'o' and instance.borrower %}
                                            ({{ instance.borrower.username }})
                                        {% endif %}
                                    </li>
                                {% endfor %}
                            </ul>
                        </div>
                    {% endif %}
                    
                    <form method="post">
                        {% csrf_token %}
                        <div class="d-flex gap-2">
                            <button type="submit" class="btn btn-danger">
                                <i class="bi bi-trash me-1"></i>Yes, Force Delete Everything
                            </button>
                            <a href="{% url 'book-detail' object.pk %}" class="btn btn-secondary">
                                <i class="bi bi-x-circle me-1"></i>Cancel
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 